package ua.kpi_java_training.zabrodskyi.module2;

import java.util.Scanner;

/**
 * @author Maksym Zabrodskyi
 * @version 10-Jun-2013
 */
public class Initialization {

    private Pool pool;
    private int widthPool;
    private int heightPool;
    private int numberPredators;
    private int numberVictims;
    private int lengthLife;

    public void setUp() {
        Scanner scanner = new Scanner(System.in);
        setPool(scanner);
        setPredators(scanner);
        setVictims(scanner);
        setLengthLife(scanner);
    }

    private void setPredators(Scanner scanner) {
        numberPredators = Input.getPositiveNumber(scanner,
                "Enter the number of predators:");
//        numberPredators = 1;
        for (int number = 0; number < numberPredators; number++) {
            if (pool.hasFreeUnit()) {
                Predator predator = new Predator();
                predator.setPosition(Random.getFreePosition(pool));
                pool.add(predator);
            }
        }
    }

    private void setVictims(Scanner scanner) {
        numberVictims = Input.getPositiveNumber(scanner,
                "Enter the number of victims:");
//    	numberVictims = 4;
        for (int number = 0; number < numberVictims; number++) {
            if (pool.hasFreeUnit()) {
                Victim victim = new Victim();
                victim.setPosition(Random.getFreePosition(pool));
                pool.add(victim);
            }
        }
    }

    public Pool getPool() {
        return this.pool;
    }

    private void setPool(Scanner scanner) {
        widthPool = Input.getPositiveNumber(scanner, "Enter width of pool:");
        heightPool = Input.getPositiveNumber(scanner,
                "Enter height of pool:");
//        widthPool = 10;
//        heightPool = 10;
        pool = new Pool(widthPool, heightPool);
    }

    public int getLengthLife() {
        return lengthLife;
    }

    private void setLengthLife(Scanner scanner) {
        lengthLife = Input.getPositiveNumber(scanner,
                "Enter the number of cycles of life:");
//        lengthLife = 5;
    }

    public int getNumberPredators() {
        return numberPredators;
    }

    public int getNumberVictims() {
        return numberVictims;
    }

}